/**
new URLSelect({'id':'selectId','value':'selectValue','url':'','valueField':'','textField':'','listField':''})
valueField: default value
textField: default text
listField: if undefined ,then default data is a array
*/

function URLSelect(param)
{
	try
	{
		var selectId=param.id;
		var select=document.getElementById(selectId);
		if(select==undefined){return;}
		var selectValue=param.value;
		var valueField="value";
		var textField="text";
		if((param.valueField!=undefined)&&(param.valueField.length>0)){valueField=param.valueField;}
		if((param.textField!=undefined)&&(param.textField.length>0)){textField=param.textField;}
		var listField=param.listField;
		if(listField==undefined){listField="";}
		var params="selectId="+selectId+"&valueField="+valueField+"&textField="+textField+"&listField="+listField+"&selectValue="+selectValue;
		new ajax({'url':param.url,'params':params,'success':function(data,obj)
			{
			try
			{
				var json=toJson(data);
				var select=document.getElementById(obj.map["selectId"]);
				select.options.length=0;
				var list=json;
				var textField=obj.map["textField"];
				var valueField=obj.map["valueField"];
				var listField=obj.map["listField"];
				if((listField!=undefined)&&(listField.length>0)){list=json[listField];}
				var selectedIndex=-1;
				for(var i=0;i<list.length;i++)
				{
					var item=list[i];
					select.options.add(new Option(item[textField],item[valueField])); 
					if(obj.map["selectValue"] == item[valueField])
					{
						selectedIndex=i;
					}
				}
				select.selectedIndex=selectedIndex;
				if(typeof(select.onchange)=="function")
				{
					select.onchange();
				}
			}catch(e){alert("URLSelect error2 : "+e.message);}
				
			}});
		
	}catch(e){alert("URLSelect error1 : "+e.message);}

	
}
